package After826.Thread;

import java.util.Timer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadPool {
    public static void main(String[] args) {
        //new CacheThreadPool//        ExecutorService executor = Executors.newCachedThreadPool();
//        for (int i = 0; i < 10; i++) {
//            final int index = i;
//            try {
//                Thread.sleep( (index *1000));
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            executor.execute(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println(index);
//                }
//            });
//        }
        //new FixedThreadPool
//        ExecutorService ThreadPool = Executors.newFixedThreadPool(3);
//        for (int i = 0; i < 10 ;i ++ ){
//            final int index = i;
//            ThreadPool.execute(new Runnable() {
//                @Override
//                public void run() {
//                    try {
//                        Thread.sleep(2000);
//                    } catch (InterruptedException e) {
//                        throw new RuntimeException(e);
//                    }
//                    System.out.println(index);
//                }
//            });
//            }
//        }
        //new ScheduleThreadPool
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
        scheduledThreadPool.schedule(new Runnable() {

            @Override
            public void run() {
                System.out.println("delay 3 seconds");
            }
        }, 3, TimeUnit.SECONDS);
    }
}


